package com.ucar.ui.advise;

import java.util.HashMap;
import java.util.Map;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;

import com.ucar.R;
import com.ucar.net.BaseResponse;
import com.ucar.net.Callback;
import com.ucar.net.NetRequest;
import com.ucar.ui.base.BaseActivity;

public class AdviseActivity extends BaseActivity {
	private EditText et_msg2our;
	private String content;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setBaseTitleContent(R.layout.activity_sendmsg, R.string.advise);
	}

	@Override
	public void onInit() {
		et_msg2our = find(R.id.et_msg2our);
		setLeftImage(R.drawable.icon_arrow);
		setRightText(R.string.commit, new OnClickListener() {
			@Override
			public void onClick(View v) {
				content = et_msg2our.getText().toString().trim();
				if (TextUtils.isEmpty(content)) {
					showToast(R.string.input_adviseinfo);
					return;
				}
				sendMsgToUs();
			}
		});
	}

	@Override
	public void onFindViews() {

	}

	@Override
	public void onInitViewData() {

	}

	@Override
	public void onBindListener() {
	}

	private void sendMsgToUs() {
		// Tag used to cancel the request
		String tag = "tag_send_advise";
		NetRequest.getInstance(this).get(new Callback() {
			private String token;

			@Override
			public void onPreExecute() {
				toShowProgressMsg(getString(R.string.sending));
			}

			@Override
			public void onFinished() {
				toCloseProgressMsg();
			}

			@Override
			public void onSuccess(BaseResponse response) {
				showToast(R.string.sendAdviseSuccessed);
				finish();
			}

			@Override
			public void onFailed(String msg) {
				showToast(msg);
			}

			@Override
			public Map<String, String> getParams() {
				token = mSpUtil.getToken();
				content = et_msg2our.getText().toString().trim();
				Map<String, String> params = new HashMap<String, String>();
				params.put("url", "app/feedback");
				params.put("content", content);
				params.put("token", token);
				return params;
			}
		}, tag);
	}
}
